package com.no1.zy.controller;

import com.no1.zy.pojo.Student;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.*;

@RequestMapping("/stu")
@Controller
@Slf4j
public class StudentController {

    @RequestMapping("iteList")
       public String iteratorList(Model model){
        List<Student> stuList = new ArrayList<>();
        stuList.add(new Student(1001,"张娅","女",null,18));
        stuList.add(new Student(1002,"张兰","女",null,18));
        stuList.add(new Student(1003,"张妹","女",null,18));
        stuList.add(new Student(1004,"张美女","女",null,18));
        stuList.add(new Student(1004,"张美女","女",null,18));
        Calendar cal=new GregorianCalendar();
        cal.set(2004,5,8);
        Student stu1=new Student(1005,"周五","男",cal.getTime(),25);
     Student stu2=new Student(1006,"周六","男", Date.from(
             LocalDateTime.of(2006,4,3,1,34,34).
                     atZone(ZoneId.systemDefault()).toInstant()),26);
          stuList.add(stu1);
          stuList.add(stu2);
        model.addAttribute("stuList",stuList);
        return "stu/show";
        }

    @RequestMapping("iteMap")
    public String iteratorMap(Model model) {
        Map<String, Student> stuMap = new HashMap<>();
        stuMap.put("s1", new Student(1001, "赵一", "男", null, 21));
        stuMap.put("s2", new Student(1002, "钱二", "女", null, 22));
        stuMap.put("s3", new Student(1003, "孙三", "男", null, 23));
        model.addAttribute("stuMap", stuMap);
        return "stu/show2";


        }


}

